# coding: utf-8
# テクスチャをコンバート

import os
from xml.dom import minidom

# ================================================================
# 
# ================================================================
def getRightUnderChild(node, name):
    for child in node.childNodes:
        if child.nodeType in [child.TEXT_NODE, child.COMMENT_NODE]: continue
        if child.tagName == name: return child
    
    return None

# ================================================================
# 
# ================================================================
def convertTexture(texture_name, texture_kind):
    print(texture_name, texture_kind)

# ================================================================
# 
# ================================================================
def convertTextureFromElement(element):
    image = getRightUnderChild(element, "image")
    textureKindElement = getRightUnderChild(element, "textureKind")
    
    if image == None: return 
    texture_name = image.childNodes[0].data
    
    texture_kind = "Single"
    if textureKindElement != None: texture_kind = textureKindElement.childNodes[0].data
    
    convertTexture(texture_name, texture_kind)

# ================================================================
# 
# ================================================================
def convertTextureFromXML(file_name):
    xdoc = minidom.parse(file_name)
    
    part_list = xdoc.getElementsByTagName("part")
    
    for part in part_list:
        convertTextureFromElement(part)

    

# ================================================================
# main時のtest
# ================================================================
def main():
    file_list = ["sample.xml", "sample2.xml"]
    
    for file in file_list:
        convertTextureFromXML(file)

# メイン時
if __name__ == '__main__': main()



